import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/home/goods_detail/entity/goods_detail_data.dart';
import 'package:flutter_shop/r.dart';
import 'package:flutter_shop/res/styles.dart';
import 'package:flutter_shop/utils/utils.dart';
import 'package:flutter_shop/widget/load_image.dart';
import 'package:flutter_shop/widget/page_state_widget.dart';

///商品评论部分
class GoodsCommentPart extends StatelessWidget {
  final List<GoodsDetailDataGoodComments> list;
  final String pic;

  GoodsCommentPart({Key key, this.list, this.pic}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        child: Column(
          children: <Widget>[
            (list == null || list.isEmpty)
                ? Container(
                    padding: Paddings.common,
                    child: PageStateWidget(
                      child: Gaps.empty,
                      state: PageStateType.EMPTY,
                      showRetry: false,
                      tip: "暂无评论!",
                    ),
                  )
                : ListView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: list.length,
                    itemBuilder: _buildItem,
                    shrinkWrap: true,
                  ),
            LoadImage(pic),
          ],
        ),
      ),
    );
  }

  ///评论item
  Widget _buildItem(context, index) {
    GoodsDetailDataGoodComments item = list[index];

    return RawMaterialButton(
      fillColor: Colors.white,
      onPressed: () {
        Utils.showToast(item.comments);
      },
      child: Container(
        width: double.infinity,
        padding: Paddings.common,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(item.userName, style: TextStyles.common_text),
            Text(item.comments, style: TextStyles.common_text),
            Text("${DateUtil.getDateStrByMs(item.discussTime)}", style: TextStyles.common_text),
          ],
        ),
      ),
    );
  }
}
